package com.bdqn.SJ3CGLIB;


import org.apache.log4j.Logger;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;


import java.lang.reflect.Method;

public class IntermediaryMethodInterceptor implements MethodInterceptor {
    private Logger logger=Logger.getLogger(IntermediaryMethodInterceptor.class);
    /**
     * 被代理的目标对象
     */
    private Object target;

    public void setTarget(Object target){
        this.target=target;
    }

    public void before(){
        logger.debug("① : 前期准备。");
        logger.debug("② : 查找房源。");
        logger.debug("③ : 和卖家沟通时间。");
    }

    public void after(){
        logger.debug("④ : 后期跟踪。");
        logger.debug("⑤ : 和买家沟通意见。");
    }
    /**
     * 为代理的接口方法定义的代理业务规则
     * @param
     * @param method
     * @param
     * @return
     * @throws Throwable
     */

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        before();
        Object feedback=methodProxy.invoke(target,objects);//反射执行目标对象的实际业务
        after();
        return "看房记录: 买家回馈”"+feedback+"“";
    }
}
